from . import MemoryDetailService
from src.common.logger import getLogger
from src.modules.memory.dao import HistoryRecordDao

logger = getLogger()

def load_history_records(args):
    logger.info(f"load_history_record args: {args}")
    list = HistoryRecordDao.load_history_records(args)
    return list

def insert_history_memory(form):
    from ..model.history_record import HistoryRecord

    record = HistoryRecordDao.select_history_record(form)
    if not record:
        history_record = HistoryRecord()
        history_record.id = form.get("source_id")
        history_record.source = form.get("source")
        history_record.pattern = form.get("pattern")
        history_record.name = form.get("query")
        HistoryRecordDao.insert_history_record(history_record)

    MemoryDetailService.insert_memory_detail_user(form)

def update_history_record(form):
    HistoryRecordDao.update_history_record(form)

def delete_history_record(form):
    ids = form.get("ids").split(",")
    for id in ids:
        HistoryRecordDao.delete_history_record(id)

        MemoryDetailService.delete_memory_detail(id)
